/*
 * Copyright 2007 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package ar.pmt.gwt.client.rpc.service;



import java.util.Collection;
import java.util.Iterator;

import ar.pmt.gwt.client.recurso.control.RecursoNotifier;
import ar.pmt.gwt.client.rpc.CommonManager;
import ar.pmt.gwt.client.rpc.CommonManagerAsync;
import ar.pmt.vista.beans.RecursoBean;

import com.google.gwt.user.client.rpc.AsyncCallback;



  public class CommonServiceAsync  {

    private final CommonManagerAsync recursoRcp;

    public CommonServiceAsync() {
    	recursoRcp = CommonManager.Util.getInstance();
    }
    
    public void obtenerRecursosPorPeticion(final String uid, final RecursoNotifier recursoOut) {
    	 
    	
    	recursoRcp.getRecursosPorPeticion(uid, new AsyncCallback<Collection<RecursoBean>>() {
    	
    	
		    	public void onFailure(Throwable caught) {
		    			System.out.println("fallo");
		    			System.out.println(caught.getMessage());
		        }
		        
		    	public void onSuccess(Collection<RecursoBean> result) {  		    		
					recursoOut.setRecursosBean(result);
					recursoOut.getListener().onChange(recursoOut);
					
		        }

      });
    
    	
    }
    
    public void obtenerRecurso(final String uid, final RecursoNotifier recursoOut) {
    	 
    	recursoRcp.getRecurso(uid, new AsyncCallback<RecursoBean>() {
   
		    	public void onFailure(Throwable caught) {
		    		recursoOut.setRecursoBean(new RecursoBean());
					recursoOut.getListener().onChange(recursoOut);
		        }

				public void onSuccess(RecursoBean recurso) {
					recursoOut.setRecursoBean(recurso);
					recursoOut.getListener().onChange(recursoOut);
					
				}

      });
    
    	
    }
    
 


}
